<?php

$cheat   = 0; //mettre a 1 pour afficher la solution
$local   = true; //utilisation local ou distante !

$url="";

if($local){
	$url = explode("/", $_SERVER['REQUEST_URI']);
	$url[count($url)-1]="game.php";
	$url = implode("/", $url);
	$url = "http://".$_SERVER['SERVER_NAME'].$url;
}else{
	$url="http://studio11.hyperhorizon.net/lp/master/game.php";
}

$action  = @$_REQUEST['action'];
$jeu     = @$_REQUEST['jeu'];
$id      = @$_REQUEST['id'];
$nbTour  = 12;

$url .= "?";
if ($action != "") {$url .= "action=".$action;}
if ($jeu    != "") {$url .= "&jeu=".$jeu;}
if ($id     != "" && $action != "commencer") {$url .= "&id=".$id;}
$url .= "&cheat=1";

$handle = fopen($url, "r");

	
if (!$handle) 
{
	print "erreur<hr>";
	exit;
} 
else
{
	$page = "";
	while (!feof($handle)) {
  		$page .= fgets($handle, 4096);
	}
	
	$repTab = split('#', $page, 6);
	if (count($repTab) > 4) {
		if($repTab[1]>$nbTour+1){
			unset($repTab[5]);
			$repTab[4]="badcheatdetect";
			$repTab[3]="0";
			$repTab[2]="0";
			$newHand = implode('#', $repTab);
			$newHand .="#";
			echo $newHand;
		}else{
			if (intval($repTab[1]) <= intval($nbTour) && $cheat==0) {
				unset($repTab[5]);
				$newHand = implode('#', $repTab);
				$newHand .="#";
				echo $newHand;
			} else {
				echo $page;
			}
		}
		
	} else {
		print "erreur<hr>";
		exit;
	}
}
?>

